import { _decorator, Component, Label, Node } from 'cc';
import ViewBase from '../engine/ViewBase';
import { UI_Cache_Type, UI_Config } from '../engine/UI_Config';
import { BundleConfig } from '../config/BundleConfig';
import { UIManager } from '../engine/UIManager';
const { ccclass, property } = _decorator;

@ccclass('ui/ViewTip')
export class ViewTip extends ViewBase {

    //提示类型 
    public static TipType = {
        Normal: 0, //正常
        Success: 1, //成功
        Fail: 2, //失败
    }

    //ui 配置 
    public static uiConfig: UI_Config = new UI_Config("ViewTip",
        UI_Cache_Type.always, false, BundleConfig.main);


    private tipsStr: string; //提示内容
    private tipType: number = ViewTip.TipType.Success; //提示类型

    public onInitChild(tipsStr: string, tipType: number) {
        this.tipsStr = tipsStr;
        this.tipType = tipType;
    }


    start(): void {
        super.start();
        let bgNode: Node = this.findChild(this.contentNode, "bg");
        this.hideAllChildren(bgNode);
        if (this.tipType == ViewTip.TipType.Success) {
            let lbSuccess: Label = this.getChild(bgNode, "lbSuccess", Label);
            lbSuccess.node.active = true
            lbSuccess.string = this.tipsStr;
        }
        else if (this.tipType == ViewTip.TipType.Normal) {
            let lbNormal: Label = this.getChild(bgNode, "lbNormal", Label);
            lbNormal.node.active = true
            lbNormal.string = this.tipsStr;
        }
        else if (this.tipType == ViewTip.TipType.Fail) {
            let lbFail: Label = this.getChild(bgNode, "lbFail", Label);
            lbFail.node.active = true
            lbFail.string = this.tipsStr;
        }
        this.scheduleOnce(() => {
            UIManager.instance.closeView(this);
        }, 3)
    }
}

